﻿using CallApi.Model;
using CallApi.Response;
using CallApi.RestApi;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace CallApi
{
    public class CallApiClient
    {

        public static ResultResponse CallStartDevice(string host, string apiSecret, DeivceStartModel model)
        {
            if (string.IsNullOrWhiteSpace(host))
                throw new ArgumentNullException("host 不能为空");
            if (string.IsNullOrWhiteSpace(apiSecret))
                throw new ArgumentNullException("apiSecret 不能为空");
            model.RequestTime = DateTime.Now.ToString();
            model.SetSign(apiSecret);
            RestSharpClient client = new RestSharpClient(host);
            RestSharp.RestRequest request = new RestSharp.RestRequest() { Resource = "/api/Order/StartDevice", Method = Method.POST };

            var json = JsonConvert.SerializeObject(model);
            request.AddParameter("application/json", json, ParameterType.RequestBody);

            var response = client.Execute<ResultResponse>(request);
            return response;
        }
    }
}
